home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 126-150 / disk_138 / foreach / foreach.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  1KB  |  64 lines

  1. #include <stdio.h>
  2. #include <dos.h>
  3. #include <string.h>
  4. #include <libraries/dosextens.h>
  5.  
  6. /* Compiled with Lattice v4.0 */
  7.  
  8. void main(argc, argv)
  9. int argc;
  10. char **argv;
  11. {
  12.     char *filestring;
  13.     char *commandstring;
  14.     int error;
  15.     int i;
  16.     struct FILEINFO info;
  17.     int attr=0;
  18.     
  19.     /* One could really look more at the arguments more here... */
  20.     
  21.     if (argc<3)
  22.     {
  23.         printf("Usage is %ls <filepattern> <command> <extra args>\n", argv[0]);
  24.         exit(0);
  25.     }
  26.     
  27.     /* Get filepattern and command to apply */
  28.     
  29.     filestring=strdup(argv[1]);
  30.     commandstring=strdup(argv[2]);
  31.     
  32.     /* Make sure command gets all the supplied args.. */
  33.     
  34.     for(i=3;i<argc;i++)
  35.     {
  36.         strcat(commandstring, " ");
  37.         strcat(commandstring, argv[i]);
  38.     }
  39.     
  40.     strcat(commandstring, " ");
  41.         
  42.     if((error=dfind(&info, filestring, attr))!=0)
  43.     {
  44.         printf("\nNo file named %ls", filestring);
  45.         exit(0);
  46.     } 
  47.     
  48.     do 
  49.     if(Execute(strcat(strdup(commandstring), info.fib_FileName),0,0)==0)
  50.     {
  51.         printf("Execute failed with command %ls\n and filename %ls\n",
  52.         commandstring, info.fib_FileName);
  53.         exit(0);
  54.     }
  55.     
  56.     /* First strdup to create an untouched copy of commandstring, then */
  57.     /* execute it with current filename. */
  58.     
  59.     while(!dnext(&info));  /* Nice test. */
  60.     
  61.     printf("\nDone!\n");
  62.     
  63. }
  64.